/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Client;

import java.rmi.Naming;
import javax.swing.JOptionPane;
import server.Server_Client_Interface;

/**
 *
 * @author 김기민
 */
public class JoinUI extends javax.swing.JFrame {

    LoginUI ui;
   
    private String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }


    /**
     * Creates new form JoinUI
     */
    public JoinUI() {
        initComponents();
    }

   public JoinUI(String userid) {

        setId(userid);
       initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButton_TypeA = new javax.swing.JButton();
        jButton_TypeB = new javax.swing.JButton();
        jButton_TypeC = new javax.swing.JButton();
        jButton_TypeD = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("굴림", 1, 18)); // NOI18N
        jLabel1.setText("This is Insurunce Join Page");

        jLabel2.setForeground(new java.awt.Color(204, 0, 0));
        jLabel2.setText("* If you already join Insurunce, you can change your insurunce by cliking ");

        jButton_TypeA.setText("Join Type A");
        jButton_TypeA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_TypeAActionPerformed(evt);
            }
        });

        jButton_TypeB.setText("Join Type B");
        jButton_TypeB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_TypeBActionPerformed(evt);
            }
        });

        jButton_TypeC.setText("Join Type C");
        jButton_TypeC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_TypeCActionPerformed(evt);
            }
        });

        jButton_TypeD.setText("Join Type D");
        jButton_TypeD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonType_DActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(22, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 432, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(layout.createSequentialGroup()
                                        .addGap(68, 68, 68)
                                        .addComponent(jLabel1))))
                .addGroup(layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jButton_TypeC, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton_TypeA, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE))
                        .addGap(97, 97, 97)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jButton_TypeB, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE)
                                .addComponent(jButton_TypeD, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jButton_TypeA, javax.swing.GroupLayout.DEFAULT_SIZE, 44, Short.MAX_VALUE)
                                .addComponent(jButton_TypeB, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(39, 39, 39)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jButton_TypeC, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)
                                .addComponent(jButton_TypeD, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap(50, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    private void jButton_TypeAActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        
          try {
           Server_Client_Interface rmi = (Server_Client_Interface) Naming.lookup("rmi://localhost/MyRMIserver");
           
           if(rmi.join(getId(), 2)==true)
           {JOptionPane.showMessageDialog(null, " Success!, You join Type A");
            new LoginUI().setVisible(true);
            dispose();
           }
           } catch (Exception e) {
            System.err.println("RMIClient exception : " + e.toString());
        }
            
            
        
    }

    private void jButton_TypeBActionPerformed(java.awt.event.ActionEvent evt) {
        try {
           Server_Client_Interface rmi = (Server_Client_Interface) Naming.lookup("rmi://localhost/MyRMIserver");
           
           if(rmi.join(getId(), 3)==true)
           {JOptionPane.showMessageDialog(null, " Success!, You join Type B");
            new LoginUI().setVisible(true);
            dispose();
           }
           } catch (Exception e) {
            System.err.println("RMIClient exception : " + e.toString());
        }

    }

    private void jButton_TypeCActionPerformed(java.awt.event.ActionEvent evt) {
         try {
           Server_Client_Interface rmi = (Server_Client_Interface) Naming.lookup("rmi://localhost/MyRMIserver");
           
           if(rmi.join(getId(), 4)==true)
           {JOptionPane.showMessageDialog(null, " Success!, You join Type C");
            new LoginUI().setVisible(true);
            dispose();
           }
           } catch (Exception e) {
            System.err.println("RMIClient exception : " + e.toString());
        }
    }

    private void jButtonType_DActionPerformed(java.awt.event.ActionEvent evt) {
        try {
           Server_Client_Interface rmi = (Server_Client_Interface) Naming.lookup("rmi://localhost/MyRMIserver");
           
           if(rmi.join(getId(), 5)==true)
           {JOptionPane.showMessageDialog(null, " Success!, You join Type D");
            new LoginUI().setVisible(true);
            dispose();
           }
           } catch (Exception e) {
            System.err.println("RMIClient exception : " + e.toString());
        }

    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(JoinUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JoinUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JoinUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JoinUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JoinUI().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton_TypeD;
    private javax.swing.JButton jButton_TypeA;
    private javax.swing.JButton jButton_TypeB;
    private javax.swing.JButton jButton_TypeC;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    // End of variables declaration                   
}
